




#import "YSLoginViewController.h"
#import "UIView+CZFrame.h"
#import "YSForGetpassViewController.h"
#import "YSRegisterViewController.h"









#import "YSMainTabBarViewController.h"






#import "LoadVcManager.h"
@interface YSLoginViewController ()


@property (weak, nonatomic) IBOutlet UITextField *username_tx;

@property (weak, nonatomic) IBOutlet UITextField *password_tx;
@property (weak, nonatomic) IBOutlet UIButton *longin_btn;
@property (weak, nonatomic) IBOutlet UIButton *register_btn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *name_to_top;
@property (weak, nonatomic) IBOutlet UIButton *save_btn;
@property (weak, nonatomic) IBOutlet UIButton *forget_btn;
@property (weak, nonatomic) IBOutlet UIView *nameview;
@property (weak, nonatomic) IBOutlet UIView *passview;
@end

@implementation YSLoginViewController
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.view endEditing:YES];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
//    self.nametotop.constant = [UIScreen mainScreen].bounds.size.height*0.4;
     self.name_to_top.constant = [UIScreen mainScreen].bounds.size.height*0.45;
    
//    self.view.backgroundColor =
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeViewFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
}

- (void)viewDidLayoutSubviews{
    
    
    [super viewDidLayoutSubviews];
    
//    self.username_tx.h = 50 ;
//    self.password_tx.h = 50;
    self.longin_btn.h = 40;
    self.register_btn.h = 40;
    
    [self settoyuanWithview:self.longin_btn];
    [self settoyuanWithview:self.register_btn];
    
    [self settoyuanWithview:self.nameview];
    [self settoyuanWithview:self.passview];
    
    [self.save_btn setImage:[UIImage imageNamed:@"save"] forState:UIControlStateNormal];
    [self.save_btn setImage:[UIImage imageNamed:@"savesel"] forState:UIControlStateSelected];
    
}

// 设置圆角的方法
- (void)settoyuanWithview:(UIView*)view {
    view.layer.cornerRadius = 5 ;
    view.layer.masksToBounds = YES;
}

// 保存密码

- (IBAction)savepass:(id)sender {
    
    self.save_btn.selected = !self.save_btn.selected;
}
// 登录
- (IBAction)login:(UIButton *)sender {
    [self presentViewController:[[YSMainTabBarViewController alloc] init ]animated:YES completion:nil];
}

// 注册
- (IBAction)registerbtnclick:(UIButton *)sender {
//    YSLoginViewController* VC = [];
   [self presentViewController:[LoadVcManager sbVCWithsbname:@"YSRegisterViewController"]  animated:YES completion:nil];
}


// 忘记密码
- (IBAction)ForGetpass:(UIButton *)sender {
    
    [self presentViewController:[LoadVcManager sbVCWithsbname:@"YSForGetpassViewController"] animated:YES completion:nil];
    
}

-(void)changeViewFrame:(NSNotification *)noti{
    //1.获取 结束时候的Frame即可
//    NSLog(@"%@",noti);
    //2.获取结束的Frame
    CGRect endRect =  [noti.userInfo[@"UIKeyboardFrameEndUserInfoKey"]CGRectValue];
    //拿 结束的Frame中的y值 跟界面的高度做减法 得到 最终 控制器的View 的y值
    CGFloat endY = endRect.origin.y-self.view.frame.size.height+200;
    
    //设置给控制器的View的Frame即可
    CGRect oldFrame=self.view.frame;
    if (endY>0) {
        endY = 0;
    }
    oldFrame.origin.y=endY;
    
    
    self.view.frame=oldFrame;
}





@end
